<?php
/*
 *      bloc.class.php
 *
 *      Copyright 2010 Patrice Ferlet <metal3d@gmail.com>
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

// $Id: block.class.php 19 2010-12-14 22:46:23Z Metal3d $
// $HeadURL: http://valaya.googlecode.com/svn/trunk/utils/block.class.php $

/**
 *  Bloc class, this class is usually called from template
 * */
class Block {

	private $content;

	/**
	 * Get bloc content. Returned Bloc instance has got __toString() method, so Bloc can be
	 * printed by "echo $bloc;"
	 *
	 * @param string $name
	 * @return Bloc $instance
	 * */
	function get($name) {
		$r = new self();
		$name =explode('/',$name);
		ob_start();
		include( _config('modulepath','project').$name[0].'/blocks/'.$name[1].'.block.php');
		$r->content = ob_get_clean();
		return $r ;
	}

	/**
	 * Ask to display the Bloc content
	 * */
	function display() {
		echo $this->content;
	}

	function __toString(){
		return $this->content;
	}

}
